home *** CD-ROM | disk | FTP | other *** search
/ Night Owl 6 / Night Owl's Shareware - PDSI-006 - Night Owl Corp (1990).iso / 008a / fgdemo10.zip / FUNDMTLS.C < prev    next >
Text File  |  1991-10-05  |  14KB  |  617 lines

  1. /**********************************************************************\
  2. *                                                                      *
  3. *  fundmtls.c -- graphics fundamentals: points, lines, rects, etc.     *
  4. *                                                                      *
  5. \**********************************************************************/
  6.  
  7. #include "defs.h"
  8.  
  9. /**********************************************************************\
  10. *                                                                      *
  11. *  do_circles -- draw a bunch of circles                               *
  12. *                                                                      *
  13. \**********************************************************************/
  14.  
  15. do_circles()
  16. {
  17.    register int i;
  18.    int x1,x2,y1,y2;
  19.  
  20.    /* establish clipping limits */
  21.  
  22.    x1 = 0;
  23.    x2 = xlimit;
  24.    y1 = menu_bottom;
  25.    y2 = ylimit;
  26.  
  27.    fg_setclip(x1,x2,y1,y2);
  28.  
  29.    /* clear bottom part of screen */
  30.  
  31.    fg_mousevis(OFF);
  32.    if (mode06 || mode11)
  33.      fg_setcolor(0);
  34.    else
  35.      fg_setcolor(1);
  36.    fg_rect(x1,x2,y1,y2);
  37.  
  38.    /* move to the center of the screen */
  39.  
  40.    x1 = xlimit / 2;
  41.    y1 = (ylimit + menu_bottom) / 2;
  42.    fg_move(x1,y1);
  43.  
  44.    /* draw concentric circles */
  45.  
  46.    x2 = 4;
  47.    fg_setcolor(15);
  48.    for (i = 0; i < 25; i++)
  49.    {
  50.       fg_circle(x2);
  51.       x2 += 8;
  52.    }
  53.  
  54.    /* wait for a keystroke */
  55.  
  56.    fg_mousevis(ON);
  57.    wait_for_keystroke();
  58.  
  59.    /* restore clipping limits */
  60.  
  61.    fg_setclip(0,fg_getmaxx(),0,fg_getmaxy());
  62.  
  63.    /* restore the screen and return to the menu */
  64.  
  65.    fg_mousevis(OFF);
  66.    fg_restore(0,xlimit,menu_bottom,ylimit);
  67.  
  68.    fg_mousevis(ON);
  69.    redraw = TRUE;
  70.  
  71.    return(OK);
  72. }
  73.  
  74. /**********************************************************************\
  75. *                                                                      *
  76. *  do_clip -- do those lines, clipped to a small rectangle             *
  77. *                                                                      *
  78. \**********************************************************************/
  79.  
  80. int do_clip()
  81. {
  82.    register int i,j;
  83.    int x1,x2,y1,y2;
  84.    int xinc;
  85.  
  86.    static int lcolor[] = {2,1,9,11,11,9,1,2};
  87.  
  88.    /* establish clipping limits - small rectangle in middle of screen */
  89.  
  90.    fg_setclip(135,510,menu_bottom+55,ylimit-55);
  91.  
  92.    /* clear bottom of screen */
  93.  
  94.    fg_mousevis(OFF);
  95.    fg_restore(0,xlimit,menu_bottom,ylimit);
  96.    fg_setcolor(15);
  97.    fg_rect(135,510,menu_bottom+55,ylimit-55);
  98.  
  99.    /* draw horizontal lines */
  100.  
  101.    fg_setcolor(0);
  102.    for (i = menu_bottom; i < ylimit; i+=40)
  103.    {
  104.       for (j = 0; j < 8; j++)
  105.       {
  106.          if (mode14 || mode16)
  107.             fg_setcolor(lcolor[j]);
  108.  
  109.          y1 = i + 3*j;
  110.          fg_move(0,y1);
  111.          fg_draw(xlimit,y1);
  112.  
  113.       }
  114.    }
  115.  
  116.    /* draw vertical lines */
  117.  
  118.    y1 = menu_bottom;
  119.    y2 = ylimit;
  120.    for (i = 0; i < 640; i+=60)
  121.    {
  122.       for (j = 0; j < 8; j++)
  123.       {
  124.          if (mode14 || mode16)
  125.             fg_setcolor(lcolor[j]);
  126.  
  127.          x1 = i + 3*j;
  128.          fg_move(x1,y1);
  129.          fg_draw(x1,y2);
  130.       }
  131.    }
  132.  
  133.    /* draw red diagonal lines */
  134.  
  135.    y1 = menu_bottom;
  136.    y2 = ylimit;
  137.    xinc = ylimit - menu_bottom;
  138.    fg_setcolor(12);
  139.    for (x1 = -640; x1 < 640; x1+=60)
  140.    {
  141.       x2 = x1 + xinc;
  142.       fg_move(x1,y1);
  143.       fg_draw(x2,y2);
  144.    }
  145.  
  146.    y1 = menu_bottom;
  147.    y2 = ylimit;
  148.    xinc = ylimit - menu_bottom;
  149.  
  150.    /* draw red diagonal lines */
  151.  
  152.    fg_setcolor(4);
  153.    for (x1 = 0; x1 < 1280; x1+=60)
  154.    {
  155.       x2 = x1-xinc;
  156.       fg_move(x1,y1);
  157.       fg_draw(x2,y2);
  158.    }
  159.  
  160.    /* wait for a keystroke or mouse button */
  161.  
  162.    fg_mousevis(ON);
  163.    wait_for_keystroke();
  164.  
  165.    /* clear the screen and return to the menu */
  166.  
  167.    fg_mousevis(OFF);
  168.    fg_setclip(0,fg_getmaxx(),0,fg_getmaxy());
  169.    fg_restore(0,xlimit,menu_bottom,ylimit);
  170.  
  171.    fg_mousevis(ON);
  172.    redraw = TRUE;
  173.    return(OK);
  174. }
  175.  
  176. /**********************************************************************\
  177. *                                                                      *
  178. *  do_ellipses -- draw a bunch of elipses                              *
  179. *                                                                      *
  180. \**********************************************************************/
  181.  
  182. do_ellipses()
  183. {
  184.    register int i;
  185.    int x1,x2,x3,y1;
  186.  
  187.    /* clear the screen */
  188.  
  189.    fg_mousevis(OFF);
  190.    if (mode06 || mode11)
  191.      fg_setcolor(1);
  192.    else
  193.      fg_setcolor(9);
  194.    fg_rect(0,xlimit,menu_bottom,ylimit);
  195.  
  196.    /* move to the center of the screen */
  197.  
  198.    x1 = xlimit / 2;
  199.    y1 = (ylimit + menu_bottom) / 2;
  200.    fg_move(x1,y1);
  201.  
  202.    /* draw concentric ellipses */
  203.  
  204.    x2 = 4;
  205.    x3 = 1;
  206.    fg_setcolor(0);
  207.    for (i = 0; i < 80; i++)
  208.    {
  209.       fg_ellipse(x2,x3);
  210.       x2 += 3;
  211.       x3++;
  212.    }
  213.  
  214.    /* wait for a keystroke or mouse button */
  215.  
  216.    fg_mousevis(ON);
  217.    wait_for_keystroke();
  218.  
  219.    /* restore the screen and return to the menu */
  220.  
  221.    fg_mousevis(OFF);
  222.    fg_restore(0,xlimit,menu_bottom,ylimit);
  223.  
  224.    fg_mousevis(ON);
  225.    redraw = TRUE;
  226.  
  227.    return(OK);
  228. }
  229.  
  230. /**********************************************************************\
  231. *                                                                      *
  232. *  do_lines -- draw lines to create a plaid pattern                    *
  233. *                                                                      *
  234. \**********************************************************************/
  235.  
  236. do_lines()
  237. {
  238.    register int i,j;
  239.    int x1,x2,y1,y2;
  240.    int xinc;
  241.  
  242.    static int lcolor[] = {2,1,9,11,11,9,1,2};
  243.  
  244.    /* clear bottom part of screen */
  245.  
  246.    fg_mousevis(OFF);
  247.    fg_setcolor(15);
  248.    fg_rect(0,xlimit,menu_bottom,ylimit);
  249.  
  250.    /* draw horizontal lines */
  251.  
  252.    fg_setcolor(0);
  253.    for (i = menu_bottom; i < ylimit; i+=40)
  254.    {
  255.       for (j = 0; j < 8; j++)
  256.       {
  257.          if (mode14 || mode16)
  258.             fg_setcolor(lcolor[j]);
  259.  
  260.          y1 = i + 3*j;
  261.          fg_move(0,y1);
  262.          fg_draw(xlimit,y1);
  263.  
  264.       }
  265.    }
  266.  
  267.    /* draw vertical lines */
  268.  
  269.    y1 = menu_bottom;
  270.    y2 = ylimit;
  271.    for (i = 0; i < 640; i+=60)
  272.    {
  273.       for (j = 0; j < 8; j++)
  274.       {
  275.          if (mode14 || mode16)
  276.             fg_setcolor(lcolor[j]);
  277.  
  278.          x1 = i + 3*j;
  279.          fg_move(x1,y1);
  280.          fg_draw(x1,y2);
  281.       }
  282.    }
  283.  
  284.    /* draw red diagonal lines */
  285.  
  286.    y1 = menu_bottom;
  287.    y2 = ylimit;
  288.    xinc = ylimit - menu_bottom;
  289.    fg_setcolor(12);
  290.    for (x1 = -640; x1 < 640; x1+=60)
  291.    {
  292.       x2 = x1 + xinc;
  293.       fg_move(x1,y1);
  294.       fg_draw(x2,y2);
  295.    }
  296.  
  297.    y1 = menu_bottom;
  298.    y2 = ylimit;
  299.    xinc = ylimit - menu_bottom;
  300.  
  301.    /* draw red diagonal lines */
  302.  
  303.    fg_setcolor(12);
  304.    for (x1 = 0; x1 < 1280; x1+=60)
  305.    {
  306.       x2 = x1 - xinc;
  307.       fg_move(x1,y1);
  308.       fg_draw(x2,y2);
  309.    }
  310.  
  311.    /* wait for a keystroke or mouse button */
  312.  
  313.    fg_mousevis(ON);
  314.    wait_for_keystroke();
  315.  
  316.    /* restore the screen and return to the menu */
  317.  
  318.    fg_mousevis(OFF);
  319.    fg_restore(0,xlimit,menu_bottom,ylimit);
  320.  
  321.    fg_mousevis(ON);
  322.    redraw = TRUE;
  323.  
  324.    return(OK);
  325. }
  326.  
  327. /**********************************************************************\
  328. *                                                                      *
  329. *  do_paint -- draw a quartered circle, then paint around it           *
  330. *                                                                      *
  331. \**********************************************************************/
  332.  
  333. do_paint()
  334. {
  335.    int x1,x2,y1,y2;
  336.  
  337.    /* restor the screen */
  338.  
  339.    fg_mousevis(OFF);
  340.    fg_restore(0,xlimit,menu_bottom,ylimit);
  341.  
  342.    /* draw a rectangle */
  343.  
  344.    y1 = menu_bottom + scale(20);
  345.    y2 = ylimit - scale(20);
  346.    x1 = 40;
  347.    x2 = xlimit - 40;
  348.  
  349.    if (mode06 || mode11)
  350.       fg_setcolor(0);
  351.    else
  352.       fg_setcolor(11);
  353.  
  354.    fg_rect(x1,x2,y1,y2);
  355.  
  356.    /* outline the rectangle */
  357.  
  358.    if (mode06 || mode11)
  359.       fg_setcolor(1);
  360.    else
  361.       fg_setcolor(0);
  362.    draw_box(x1,x2,y1,y2);
  363.  
  364.    y1 = (ylimit + menu_bottom) / 2;
  365.    x1 = xlimit / 2;
  366.    fg_move(x1,y1);
  367.  
  368.    /* draw the circle */
  369.  
  370.    if (mode06 || mode11)
  371.       fg_setcolor(1);
  372.    else
  373.       fg_setcolor(0);
  374.    fg_circle(80);
  375.  
  376.    /* draw cross bars in the circle */
  377.  
  378.    y2 = scale(80);
  379.    fg_move(x1,y1-y2);
  380.    fg_draw(x1,y1+y2);
  381.  
  382.    x2 = 100;
  383.    fg_move(x1-x2,y1);
  384.    fg_draw(x1+x2,y1);
  385.  
  386.    /* paint each quarter of the circle */
  387.  
  388.    if (!mode06 && !mode11)
  389.    {
  390.       fg_setcolor(1);
  391.       fg_paint(x1-6,y1-6);
  392.  
  393.       fg_setcolor(2);
  394.       fg_paint(x1+6,y1+6);
  395.  
  396.       fg_setcolor(3);
  397.       fg_paint(x1+6,y1-6);
  398.  
  399.       fg_setcolor(4);
  400.       fg_paint(x1-6,y1+6);
  401.    }
  402.  
  403.    /* paint the box */
  404.  
  405.    x1 = 41;
  406.    y1 = menu_bottom + scale(20) + 1;
  407.  
  408.    if (mode06 || mode11)
  409.       fg_setcolor(1);
  410.    else
  411.       fg_setcolor(14);
  412.    fg_paint(x1,y1);
  413.  
  414.    /* wait for a keystroke or a mouse button */
  415.  
  416.    fg_mousevis(ON);
  417.    wait_for_keystroke();
  418.  
  419.    /* restore the screen and return to the menu */
  420.  
  421.    fg_mousevis(OFF);
  422.    fg_restore(0,xlimit,menu_bottom,ylimit);
  423.  
  424.    fg_mousevis(ON);
  425.    redraw = TRUE;
  426.  
  427.    return(OK);
  428. }
  429.  
  430. /**********************************************************************\
  431. *                                                                      *
  432. *  do_points -- draw a nice pattern of points                          *
  433. *                                                                      *
  434. \**********************************************************************/
  435.  
  436. do_points()
  437. {
  438.    register int i,j;
  439.    int yinc;
  440.  
  441.    /* clear the bottom part of the screen */
  442.  
  443.    fg_mousevis(OFF);
  444.    if (mode06 || mode11)
  445.      fg_setcolor(0);
  446.    else
  447.      fg_setcolor(1);
  448.    fg_rect(0,xlimit,menu_bottom,ylimit);
  449.  
  450.    yinc = scale(8);
  451.  
  452.    /* draw the patterns of points */
  453.  
  454.    fg_setcolor(15);
  455.    for (i = 5; i < xlimit; i+=20)
  456.    {
  457.       for (j = menu_bottom+2; j < ylimit; j+=yinc)
  458.          fg_point(i,j);
  459.    }
  460.  
  461.    for (i = 15; i < xlimit; i+=20)
  462.    {
  463.       for (j = menu_bottom+yinc/2+2; j < ylimit; j+=yinc)
  464.          fg_point(i,j);
  465.    }
  466.  
  467.    /* wait for a keystroke or mouse button */
  468.  
  469.    fg_mousevis(ON);
  470.    wait_for_keystroke();
  471.  
  472.    /* restore the screen and return to the menu */
  473.  
  474.    fg_mousevis(OFF);
  475.    fg_restore(0,xlimit,menu_bottom,ylimit);
  476.  
  477.    fg_mousevis(ON);
  478.    redraw = TRUE;
  479.  
  480.    return(OK);
  481. }
  482.  
  483. /**********************************************************************\
  484. *                                                                      *
  485. *  do_rects -- draw a bunch of rectangles                              *
  486. *                                                                      *
  487. \**********************************************************************/
  488.  
  489. do_rects()
  490. {
  491.    register int i,j;
  492.    int x0,x1,x2,y1,y2;
  493.    int xinc,yinc;
  494.    int color;
  495.  
  496.    x0 = 5;
  497.    x1 = x0;
  498.    xinc = (xlimit - x0 - 1) / 10;
  499.    x2 = x1 + xinc;
  500.  
  501.    yinc = (ylimit - menu_bottom) / 10;
  502.    y1 = menu_bottom;
  503.    y2 = y1 + yinc;
  504.  
  505.    color = 0;
  506.  
  507.    /* draw 100 rectangles */
  508.  
  509.    fg_mousevis(OFF);
  510.    for (i = 0; i < 10; i++)
  511.    {
  512.       for (j = 0; j < 10; j++)
  513.       {
  514.          fg_setcolor(color);
  515.          fg_rect(x1,x2,y1,y2);
  516.  
  517.          color++;
  518.          if (color > 14) color = 0;
  519.  
  520.          x1 = x2;
  521.          x2 = x1 + xinc;
  522.       }
  523.       x1 = x0;
  524.       x2 = x1 + xinc;
  525.  
  526.       y1 = y2;
  527.       y2 = y1 + yinc;
  528.    }
  529.  
  530.    /* wait for a keystroke or mouse button */
  531.  
  532.    fg_mousevis(ON);
  533.    wait_for_keystroke();
  534.  
  535.    /* restore the screen and return to the menu */
  536.  
  537.    fg_mousevis(OFF);
  538.    fg_restore(0,xlimit,menu_bottom,ylimit);
  539.  
  540.    fg_mousevis(ON);
  541.    redraw = TRUE;
  542.  
  543.    return(OK);
  544. }
  545.  
  546. /**********************************************************************\
  547. *                                                                      *
  548. *  do_text -- demonstrate ROM text                                     *
  549. *                                                                      *
  550. \**********************************************************************/
  551.  
  552. do_text()
  553. {
  554.    register int i;
  555.    register int row;
  556.    int x1,x2,y1,y2;
  557.  
  558.    static char *string[] = {
  559.    "Fastgraph allows you to display",
  560.    "ROM text, a stroke character font,",
  561.    "or define your own bitmapped font.",
  562.    "This message is displayed using",
  563.    "ROM text.  The menus use bitmapped",
  564.    "characters."
  565.    };
  566.  
  567.    fg_mousevis(OFF);
  568.  
  569.    fg_restore(0,xlimit,menu_bottom,ylimit);
  570.  
  571.    /* convert rows and columns to x's and y's */
  572.  
  573.    x1 = fg_xconvert(20);
  574.    x2 = fg_xconvert(60);
  575.  
  576.    y1 = fg_yconvert(5);
  577.    y2 = fg_yconvert(13);
  578.  
  579.    /* draw a small rectangle */
  580.  
  581.    if (mode06 || mode11)
  582.      fg_setcolor(0);
  583.    else
  584.      fg_setcolor(1);
  585.    fg_rect(x1,x2,y1,y2);
  586.  
  587.    /* draw a white boarder around the box */
  588.  
  589.    fg_setcolor(15);
  590.    draw_box(x1+1,x2-1,y1+1,y2-1);
  591.  
  592.    /* put ROM text in the box */
  593.  
  594.    row = 6;
  595.    for (i = 0; i < 6; i++)
  596.    {
  597.       fg_locate(row,23);
  598.       fg_text(string[i],strlen(string[i]));
  599.       row++;
  600.    }
  601.  
  602.    /* wait for a keystroke or mouse button */
  603.  
  604.    fg_mousevis(ON);
  605.    wait_for_keystroke();
  606.  
  607.    /* restore the screen and return to the menu */
  608.  
  609.    fg_mousevis(OFF);
  610.    fg_restore(0,xlimit,menu_bottom,ylimit);
  611.  
  612.    fg_mousevis(ON);
  613.    redraw = TRUE;
  614.  
  615.    return(OK);
  616. }
  617.